﻿//
var bidui_Canceled=false;

function ShiftTab(thisa,contentID){
	HJ$("left_content1").style.display="none";
	HJ$("left_content2").style.display="none";
	HJ$("left_content3").style.display="none";
	//HJ$("left_content4").style.display="none"; 
	HJ$("left_content5").style.display="none";
	HJ$("dic_lefttab1").className="";
	HJ$("dic_lefttab2").className="";
	HJ$("dic_lefttab3").className="";
	//HJ$("dic_lefttab4").className="";
	HJ$("dic_lefttab5").className="";
	//  
	HJ$(contentID).style.display="block";
	//$("#"+ contentID).show("fast");
	thisa.className="current";		
	return false;
}
function ShiftTab2(contentID){   
    //切换tab样式 
	HJ$("li_txtListen").className="";
	HJ$("li_txtContent").className="";
	HJ$("li_txtMytrans").className="";
	HJ$("li_txtTranslation").className="";
	HJ$("li_txtBBS").className="";  
	HJ$(contentID).className="tab_selected";
	//切换对应的内容块
	HJ$("txtListen").style.display="none";
	HJ$("txtContent").style.display="none";
	HJ$("txtTranslation").style.display="none";
	HJ$("txtMytrans").style.display="none";
	HJ$("txtBBS").style.display="none"; 
    HJ$("txtToday").style.display="none";
	//
    var targetID = contentID.split("_")[1];
	if(targetID=="txtListen" || targetID=="txtBBS"){
        if(contentID=="li_txtBBS"){
            if( iFrameBBSUrl()=="about:_blank" && bulo_topicID!=0){
                ShowLoadingStatus(true);
                if(document.location.href.indexOf(".dev.")!=-1){
                    iFrameBBSUrl("http://bulo.dev.hjenglish.com/post/voa_thread.aspx?type=group&tid="+bulo_topicID);
                }else{
                    iFrameBBSUrl("http://bulo.hjenglish.com/post/voa_thread.aspx?type=group&tid="+bulo_topicID);
                }
            }
        }
	    HJ$(targetID).style.display="block";
	}else {
        if(!isActiving || Listened){  
	        HJ$(targetID).style.display="block"; 
        }else{ 
            HJ$("link_today_bbs").innerHTML="<a href='"+ currentBBSUrl +"' target='_blank'>点击参与</a>";
            HJ$("txtToday").style.display="block";
        }
	}
	if(username=="游客" || !Listened){
	    HJ$("txtMytrans").style.display="none";
	}
	return false;
}
function iFrameBBSUrl(aUrl){
    if(aUrl){ 
        ShowLoadingStatus(true);
        try{
            HJ$("iframe_bbs").style.display="none"; 
            HJ$("iframe_bbs").src=aUrl;   
        }catch(x){ 
            try{
	            HJ$("iframe_bbs").style.display="none"; 
	            window.frames["iframe_bbs"].location=aUrl;
            }catch(e){ 
            }
        }
    }else{
        try{
            return HJ$("iframe_bbs").src; 
        }catch(x){ 
            try{ 
	            return window.frames["iframe_bbs"].location;
            }catch(e){ 
            }
        }
    }
}
function iFrameDictUrl(aUrl){
    if(aUrl){ 
        ShowLoadingStatus(true);
        try{ 
            HJ$("panel_dictframe").style.display="none"; 
            HJ$("dict_iframe").src=aUrl;   
        }catch(x){ 
            try{ 
                HJ$("panel_dictframe").style.display="none"; 
	            window.frames["dict_iframe"].location=aUrl;
            }catch(e){ 
            }
        }
    }else{
        try{
            return HJ$("dict_iframe").src; 
        }catch(x){ 
            try{ 
	            return window.frames["dict_iframe"].location;
            }catch(e){ 
            }
        }
    }
}

function iframe_bbs_loaded(){
	HJ$("iframe_bbs").style.display="block"; 
    ShowLoadingStatus(false);	    
} 
function iframe_dict_loaded(){
	HJ$("panel_dictframe").style.display="block"; 
    ShowLoadingStatus(false); 
} 

function ShowLoadingStatus(aBool, aisArticle){
    if( pagetype=="listen" ){
        HJ$("panel_loadarticling").style.display= (aBool==true)?"block":"none";
        if(aBool){
            HJ$("panel_loading_alphaBg").style.display= (aisArticle==true)?"block":"none";
        }else{
            HJ$("panel_loading_alphaBg").style.display= "none";
        }
    }else{ 
        if(aBool)
            HJ$("dic_personal_list_content").innerHTML="<img src='/images/loading.gif' align='absmiddle' /> 加载中 ...";
        HJ$("dic_personal_list_nav").style.display= (aBool==true)?"none":"block";
    }
}   
///处理比对结果
function BiDui_callback(result){ 
    if(!result.error){  
        //
        if(bidui_Canceled) 
            return; 
        //
        var MyHtmlMergeResult = result.value;
        //DraftWordCount; OrigiWordCount; ErrorWords; LostWords; resultDoc; 
        
		HJ$("bidui_loading").style.display="none";
		_NewDraftResult = {};
		_NewDraftResult.score= MyHtmlMergeResult.ScoreBF;
		_NewDraftResult.time = _HjTimer.time(); 
		_NewDraftResult.text = MyHtmlMergeResult.resultDoc;  
		_NewDraftResult.errorwords = MyHtmlMergeResult.LostWords.join("|") ;
		//
        HJ$("result_panel_content").innerHTML= MyHtmlMergeResult.resultDoc;  
        // 
        
        var html="<TABLE width='310' cellpadding='2' cellspacing='0'><TR><TD width='165'> ";
        html+= "    听写于："+ FormatDateString(new Date());
        html+= "</TD><TD> ";
        html+= "    用时："+ _HjTimer.timeformated();
        html+= "<TD></TR><TR><TD>"; 
        if(_NewDraftResult.score<60){
            html+= "正确率：<font color=red>< 60%</font> <font color=gray>(+"+ Score2Money(_NewDraftResult.score, isActiving, _NewDraftResult.time) +"分)</font>"; 
        }else{
            html+= "正确率："+ _NewDraftResult.score +"% <font color=gray>(+"+ Score2Money(_NewDraftResult.score, isActiving, _NewDraftResult.time) +"分)</font>"; 
        }
        html+= "</TD><TD> ";
        html+= "错词："+ MyHtmlMergeResult.LostWordsNumBF +"个 [<a href='###'  onclick='ShiftVisible(\"panel_errorlist\");'>详细</a>]";
        html+= "</TD></TR></TABLE> ";
        HJ$("result_panel_infocontent").innerHTML=  html; 
		HJ$("result_panel").style.display="block"; 
        HJ$("result_action_current").style.display="block";
        HJ$("bidui_loading").style.display="none"; 
        //
        HJ$("panel_autoreplybbs").style.display=((Listened)?"none":"block"); 
        if(!HJ$("autoreplybbs").disabled)
            if(!Listened){
                HJ$("autoreplybbs").checked=((username!="游客")?true:false); 
                HJ$("autoreplybbs").disabled=((username=="游客")?true:false); 
            } 
		//
        HJ$("panel_autoreplybbs").style.display = ((currentBBSUrl!="")?"block":"none");
        HJ$("result_action_history").style.display="none"; 		 
        //
        SowErrorWordsList(_NewDraftResult.errorwords.split("|"));
        HJ$("panel_errorlist").style.display="none";
        if(articleID==-1){ 
            HJ$("result_action_current").style.display="none";
            HJ$("result_action_history").style.display="none";  
        }
        if( isMatch() ){
	        if(username!="游客"){ 
		        SaveDraft() ;
	        }
        }
    }else{
        CancelBiDui(); 
        alert("因服务器通讯故障比对已取消，错误信息：“"+ result.error +"”，请复制内容、刷新后重试");
    }
}
//比对
function BiDui(diffmodel){ 
    try{							 	  
		if(isMatch() && _HjTimer.time()<300){
			alert("本次听写为比赛活动，您的听写时间过少（少于五分钟），暂时无法提交");
            return false;
		}
        if(articleID==-1 && $("#txtContent").html().length==0){
            alert("本次自定义听写未设置原文，无法比对！：）");
            return false;
        }
        bidui_Canceled=false;
        var DraftContent = $("#tbox_input").val().replace(/( ){2,}/igm, " ");
        if(DraftContent.length>0){
            if( isMatch() ){
                if(!confirm("本篇为听写比赛文章，提交比对后将 [自动保存听写稿]，确定要提交？")){
                    return false;
                }
            }else if( username!="游客" && _HjTimer.time()<120 ){
                if(!confirm("本次听写时间过短（少于2分钟），你将只获得5个听写积分，确定现在提交？")){
                    return false;
                }
            }
            //
            isListening=false;
            _HjTimer.stop(); 
            var SourceContent = $("#txtContent").html().replace(/( ){2,}/igm, " ");
            //
            var wordDifNum = currentWordcount - DraftContent.split(" ").length;
            if( Math.abs(wordDifNum)>30 ){
                if(!confirm("听写内容与原文的单词量偏差太多（"+ Math.abs(wordDifNum) +"个单词），你确定听写完了吗？")){
                    return;
                }
            } 
            PageClass.bidui(articleID, SourceContent, DraftContent , BiDui_callback); 
		    HJ$("bidui_loading").style.display="block";
		    HJ$("result_panel").style.display="none"; 
		    HJ$("input_panel").style.display="none"; 
	        if(_voaplayer_inited)
                voaPlayer().srewind(false);
        }else{
            alert("请听写完毕后再提交！");
        }
    }catch(e){
	    alert(e.message); 
    }
    return false;
}
function CancelBiDui(){
    bidui_Canceled=true;
    HJ$("bidui_loading").style.display="none";
    HJ$("result_panel").style.display="none";
    HJ$("input_panel").style.display="block";
}
//
if(document.addEventListener) {
	document.addEventListener("keydown", shortcut, false);
}else if(document.attachEvent) {
	document.attachEvent("onkeydown", shortcut);
}

//复制听写结果
function CopyDraft(aPanel, aType){
    var aCont = GetCypyableDraft(aType) 
    copyit( aCont );
    //$("#"+aPanel).html("<font color=blue>复制成功！</font>"); 
    alert("恭喜啊！复制成功：）");
}

function GetCypyableDraft(aType){ 
    var aboutHtml="<br/><span style='border: dashed 2px #e4e4e4;padding: 5px; font:normal normal 12px verdana; color: #cc0000; background-color:#fff;'>本听写稿由"+ username +"听写，来自<A href='http://voa.hjenglish.com/'><FONT color=#366900>沪江VOA听写系统</FONT></A></span><br><br>";
    aboutHtml+= ConvertResultHtml(HJ$("result_panel_content").innerHTML, aType);
    //aboutHtml+= "<br/><TABLE cellSpacing=0 cellPadding=2 width=310 style='border: dashed 2px #e4e4e4;padding: 5px; font:normal 12px verdana;color:#cc0000; background-color:#fff;'><TR><TD colspan=2><STRONG style='color: #cc0000;'>新鲜提示</STRONG>：<A href='http://bulo.hjenglish.com/group/101506/'><FONT color=#366900>专业VOA系统公测中，欢迎加入！</FONT></A></TD></TR></TABLE> ";
    return aboutHtml;
    //<div style='background-color: white;font:normal normal 12px verdana;BORDER: #e4e4e4 2px dashed; PADDING-RIGHT: 5px;  PADDING-LEFT: 5px; PADDING-BOTTOM: 5px; WIDTH: 450px; PADDING-TOP: 5px; '><STRONG style='color: #cc0000;'>新鲜提示</STRONG>：<A href='http://bulo.hjenglish.com/group/101506/'><FONT color=#366900>一起打造专业的听写平台 - VOA新版公测中，欢迎加入！</FONT></A></div>";
}

// =================== 听写相关 ==========================// 
//结束听写，提交内容进行比对
function BiduiSubmit(){ 
    BiDui(1)
}
//开始听写
function StartListen(){
	if(username=="游客"){
        if( isMatch() ){ 
            alert("本文为听写比赛活动专用，游客无法参赛，请先登陆！：）");
            return false; 
        }
		if(!confirm("游客无法保存比对结果，建议先登陆，是否继续开始听写？")){
			return false;
		}
	    if(HJ$("iframe_youke").innerHTML==""){
	        HJ$("iframe_youke").innerHTML ='<iframe src="/anovisit.aspx" width=2 height=2 frameborder=0></iframe>';
	    }
	}
    isListening=true;
    HJ$("input_panel_main").style.display="block";
    HJ$("input_panel_wait").style.display="none";  
    //开始计时等功能 
    t_onSecond=function (atimer, asecond, atimestring){
        HJ$("timepassed").innerHTML="已用时: "+ atimestring; 
    }
    if(_HjTimer==0){
        _HjTimer=new hjtimer(t_onSecond); 
    }
    _HjTimer.start(); 
    if(Listened=="True"){ 
    HJ$("btn_SaveDraft").style.display="none";
    }
    ///setTimeout("player_GetFlash().SetVariable('PlayAction','play');", 1000);
    HJ$("tbox_input").focus();
    ShiftTab(HJ$('dic_lefttab1'), 'left_content1');
    //
	if(_voaplayer_inited)
        setTimeout("voaPlayer().srewind(true);", 1000);
    HJ$("copy_panel1").innerHTML='<a href="###" onclick="CopyDraft(\'copy_panel1\', \'html\');return false;">复制结果(Html)</a>';
    HJ$("copy_panel2").innerHTML='<a href="###" onclick="CopyDraft(\'copy_panel2\', \'ubb\');return false;">复制结果(UBB)</a>'; 
}
//开始重新听写
function ReListen(){
    HJ$("input_panel").style.display="block";
    HJ$("result_panel").style.display="none"; 
    StartListen();
}
function CancelListen(){  
	if(isMatch()){ 
		alert("听写大赛无法取消听写，请继续听写并提交参赛听写稿！:)");
		return false;
	}
    isListening=false; 
    if(Listened=="True" || Listened==true){
        HJ$("input_panel").style.display="none";
        HJ$("result_panel").style.display="block";
		HJ$("btn_SaveDraft").style.display="none";
		HJ$("SaveDraft_status").innerHTML="二次听写，不提供保存！";            
    }else{
        HJ$("input_panel_main").style.display="none";  
        HJ$("input_panel_wait").style.display="block";
    }  
    //
	if(_voaplayer_inited)
        voaPlayer().srewind(false);
}

//
var DiffLevel_last=3;
function recDiffLevel_callback(result){
    if(!result.error){
        HJ$("panel_userdiflevel").innerHTML="难度级别："+ DiffLevel_last;
    }else{
        alert(result.error);
    }
}
function recDiffLevel(aId, alevel){
    if(alevel!=0){
        DiffLevel_last=alevel;
        PageClass.recDiffLevel(aId, alevel, recDiffLevel_callback);
        HJ$("panel_userdiflevel").innerHTML="<img src='/images/loading.gif' align='absmiddle'/>";
    }
}
function RenderDiffLevel(){
    var html ="<span id='panel_userdiflevel'>请评定难度：";
    html+= "<SELECT name='userdiflevel' id='userdiflevel' style='font-size:12px;border:1px solid black;'>"; 
    html+= "    <OPTION VALUE='5' style='font-size:12px;'>五级(难)</OPTION>";
    html+= "    <OPTION VALUE='4' style='font-size:12px;'>四级</OPTION>";
    html+= "    <OPTION VALUE='3' selected style='font-size:12px;'>三级</OPTION>";
    html+= "    <OPTION VALUE='2' style='font-size:12px;'>二级</OPTION>";
    html+= "    <OPTION VALUE='1' style='font-size:12px;'>一级(易)</OPTION>";
    html+= "</SELECT>";
    html+= "[<a href='###' onclick='recDiffLevel("+articleID+", HJ$(\"userdiflevel\").value);return false;'>确认</a>]</span>";
    return html;
}
//保存比对稿的回调函数
function savedraft_callback(result){   
    if(!result.error){
       ShiftNoteEnable(true);
       Listened=true;
       if(HJ$("autoreplybbs").checked){
		    autoreplayBBS();
       } else{; 
            if(currentBBSUrl.length==0){
                HJ$("SaveDraft_status").innerHTML= ("<font color=blue>保存成功！</color>"+ RenderDiffLevel() ); 
            }else{
                HJ$("SaveDraft_status").innerHTML= ("<font color=blue>保存成功！</color> [<a href='"+ currentBBSUrl +"' target='_blank'>查看帖子</a>]<br/>"+ RenderDiffLevel() ); 
            }
            HJ$("SaveDraft_status").style.display="block"; 
            HJ$("btn_SaveDraft").style.display="none"
            setTimeout("LoadArticle("+ articleID +")",500);
       }
	   HintMatchinfo();
    }else{
        HJ$("SaveDraft_status").innerHTML= "<font color=red>保存失败！"+ result.error +"</color>";
        HJ$("SaveDraft_status").style.display = "block";
    }
}
//保存比对稿
function SaveDraft(){ 
	if(username=="游客"){
		alert("游客无法保存听写稿，请先注册或登陆！");
		return true;
	}
    try{ 
        HJ$("panel_autoreplybbs").style.display = "none";
        HJ$("SaveDraft_status").style.display = "block";
        HJ$("SaveDraft_status").innerHTML = "<img src='/images/loading.gif' align='absmiddle'/> 保存中，请稍候..."; 
        HJ$("btn_SaveDraft").style.display="none";   
        PageClass.RecDraft(username, _NewDraftResult.score, articleID, _NewDraftResult.text, _NewDraftResult.errorwords, _NewDraftResult.time, savedraft_callback);
    }catch(e){
		alert(e.message);
    }
    return false;
}
//
function autoreplayBBS_callback(result){
    if(!result.error && result.value==true){  
        if(currentBBSUrl.length==0){
            HJ$("SaveDraft_status").innerHTML= ("<font color=blue>保存并回帖成功！</color>"+ RenderDiffLevel() ); 
        }else{ 
            HJ$("SaveDraft_status").innerHTML= ("<font color=blue>保存并回帖成功！</color> [<a href='"+ currentBBSUrl +"' target='_blank'>查看帖子</a>]<br/>"+ RenderDiffLevel()); 
        }
        HJ$("SaveDraft_status").style.display="block"; 
        HJ$("btn_SaveDraft").style.display="none"
    }else{
        if(currentBBSUrl.length==0){
            HJ$("SaveDraft_status").innerHTML= "<font color=red>保存成功！</color>";
        }else{  
            HJ$("SaveDraft_status").innerHTML= "<font color=red>保存成功，但回帖失败！"+ result.error +"</color>"+"<br/> [<a href='"+ currentBBSUrl +"' target='_blank'>查看帖子</a>]";
        }
        HJ$("SaveDraft_status").style.display = "block";
    }
    setTimeout("LoadArticle("+ articleID +")",500);
}

//
function autoreplayBBS(){
    var ahtml = GetCypyableDraft("html")+"　";
    if( HJ$("cbox_contest").checked ){
        ahtml = "[contest]"+ ahtml +"[/contest] ";
    }
    PageClass.autoreplayBBS(articleID, (ahtml), autoreplayBBS_callback);
}
//
function autoreplayBBSTrans_callback(result){
    if(!result.error && result.value==true){  
        HJ$("link_replybbstrans").innerHTML= "<font color=blue>回复成功！</color><a href='###' onclick='return Viewbbs(this,2);' target='_blank'>查看</a>" ;
    }else{
        HJ$("SaveDraft_status").innerHTML= "<font color=red>回复失败！请<a href='###' onclick='return autoreplayBBSTrans();'>稍后重试</a></color>"; 
    } 
}
function autoreplayBBSTrans(){ 
    if(HJ$("txtMytrans_content").value.length>0){
        HJ$("link_replybbstrans").innerHTML="<img src='/images/loading.gif' align='absmiddle'/> 回复中，请稍候...";    
        PageClass.autoreplayBBSTrans(articleID, (HJ$("txtMytrans_content").value), autoreplayBBSTrans_callback);
    }else{
        alert("保存前，请先输入翻译稿");
    }
}
//
//ubb/html
function ConvertResultHtml(html, type){ 
    if(type=="ubb"){
        //html -> ubb：只保留颜色和超链接
        html=html.replace(/<span class=(?:\")?diff(?:char)?_off(?:\")?>(.*?)<\/span>/igm, "[color=red]$1[/color]");
        html=html.replace(/<span class=(?:\")?diff(?:char)?_add(?:\")?>(.*?)<\/span>/igm, "[color=green]$1[/color]");
        html=html.replace(/<FONT color=(.*?)>(.*?)<\/FONT>/igm, "[color=$1]$2[/color]");       
        html=html.replace(/<a.*?href=\"(.*?)\".*?>(.*?)<\/a>/igm, "[url=$1]$2[/url]");  
        html=html.replace(/(<.*?>)/igm,"");     
        html+= "\n"+ HJ$("result_panel_infocontent").innerHTML;
    }else{
        //嵌入具体样式
        html=html.replace(/class=(?:\")?diff(?:char)?_off(?:\")?/igm, "style='text-decoration:line-through;color:red;'");
        html=html.replace(/class=(?:\")?diff(?:char)?_add(?:\")?/igm, "style='background: SpringGreen;'");
        html+= "<br/>"+ HJ$("result_panel_infocontent").innerHTML;
    } 
    html = html.replace(/<table/igm,  "<table style='border: dashed 2px #e4e4e4;padding: 5px; font:normal 12px verdana;color:#cc0000; background-color:#fff;'"); 
    html = html.replace(/\[.*?(href).*?\]/igm, "") ;
    return html;
}
//更新听写界面元素的相关状态
function UpdateDraftStatus(){
    //
    HJ$("panel_listen").style.display = (articleID!=0)?"block":"none";	    
    HJ$("panel_waitfor").style.display =(articleID==0)?"block":"none"; 
    HJ$("present_passage_empty").style.display = (articleID==0)?"block":"none";        
    HJ$("present_passage_info_ctn").style.display = (articleID!=0)?"block":"none";
    HJ$("present_passage_intro").style.display = (articleID!=0)?"block":"none";
    HJ$("present_passage_relative").style.display = (articleID!=0)?"block":"none";
    //
    if(articleID!=0){
        if(Listened=="True" || Listened==true){
            HJ$("input_panel").style.display="none";
            HJ$("result_panel").style.display="block";
		    HJ$("btn_SaveDraft").style.display="none"; 
            HJ$("SaveDraft_status").style.display="block"; 
		    $("#btn_SaveDraft").attr("disabled",true);
        }else{
            HJ$("input_panel").style.display="block";
            HJ$("result_panel").style.display="none";
		    HJ$("btn_SaveDraft").style.display="block";
            HJ$("SaveDraft_status").style.display="none";
            HJ$("input_panel_main").style.display="none";  
            HJ$("input_panel_wait").style.display="block";
		    $("#btn_SaveDraft").attr("disabled",false);
        }
    }
    HJ$("tbox_input").value ="";
    HJ$("panel_errorlist").style.display="none"; 
    //
    /*if(currentBBSUrl.lengh!=0 && currentBBSUrl_trans.length!=0)
        HJ$("bbs_links").style.display="block";
    else
        HJ$("bbs_links").style.display="none";*/ 	
    HJ$("bbs_link_listen").style.visibility = ((currentBBSUrl!="")?"visible":"hidden");
    HJ$("bbs_link_trans").style.visibility = ((currentBBSUrl_trans!="")?"visible":"hidden");
	
	
    //
    HJ$("link_replybbstrans").style.display = ((currentBBSUrl_trans!="")?"block":"none");
    //
    if( bbstrans_replayed ){
        HJ$("link_replybbstrans").innerHTML='<span class="gray">总结帖已回复</span>'; 
    }else{
        HJ$("link_replybbstrans").innerHTML='[<a href="###" onclick="return autoreplayBBSTrans();">回复翻译到总结贴</a>]';	        
    }
    //HJ$("txtMytrans").style.display= ((Listened)?"block":"none");
}

//网页初始化
if(pagetype=="listen"){
    $(function() {
            ShiftTab( HJ$("dic_lefttab"+ initLeftTabID), "left_content"+ initLeftTabID);
            UpdateDraftStatus(); 
            if(initErrorwords!=""){
                SowErrorWordsList( initErrorwords.split("|") );
            }
            //document.title="VOA听写  ___[F7切换暂停]___[F8 AB复读]___[F9 复读模式切换]___";
            if(bulo_topicID!=0){
                HJ$("li_txtBBS").style.display="block"; 
            }else{
                HJ$("li_txtBBS").style.display="none";	        
            } 
            ShiftNoteEnable(Listened);
            // 
            var fsize = getcookie("voafsz");
            if(fsize!="")
                ShiftFontSize_do(parseInt(fsize));
    });
}
// =================== 动态加载听写稿 ==========================// 
//渲染错词列表：words: [**, **]
function SowErrorWordsList(words){ 
    try{ 
	    var ahtml ='';
	    for(var i=0;i<words.length;i++){
		    var taskID= 100+i;
		    var word= escape(words[i]);
		    if (i%2==1)
		    {
			    ahtml+= '<li class="dropdown_word_list"><div class="dropdown_word"><a href="http://dict.hjenglish.com/w/'+ words[i] +'" class="hjdict" word="'+ word +'" target="_blank">'+ words[i] +'</a></div>';
			    ahtml+= '<div class="dropdown_add" id="panel_awd_'+ taskID +'"><a href="###" onclick="AddWord('+taskID+',\''+ word +'\');return false;" class="red"><img src="/images/btn_myword_add.gif" /></a></div></li>';
		    }
		    else
		    {
			    ahtml+= '<li class="dropdown_word_list wordpad_lists_single"><div class="dropdown_word"><a href="http://dict.hjenglish.com/w/'+ word +'" class="hjdict" word="'+ word +'" target="_blank">'+ words[i] +'</a></div>';
			    ahtml+= '<div class="dropdown_add" id="panel_awd_'+ taskID +'"><a href="###" onclick="AddWord('+taskID+',\''+ word +'\');return false;" class="red"><img src="/images/btn_myword_add.gif" /></a></div></li>';
		    }
	    }
	    HJ$('dropdown_list').innerHTML = ahtml; 
	}catch(e){ 
	    //
	}
}

//加载听写稿的回调函数
function LoadArticle_callback(result){ 
    if(!result.error){ 
        var article =result.value[0];
        var draft = result.value[1];
        var recentListens = result.value[2];
        // 
        articleID = article.aID;
        pID= article.pID;
        // 
        HJ$("programName").innerHTML =article.programName;
        // 
        isActiving = article.IsActive;
        currentWordcount = article.wordcount;
        currentArticleTags = article.tags;
        currentClassname = article.classname;
        HJ$("txtSummary").innerHTML = article.summary;
        Listened= (draft!=null);
        
        if(isActiving && !Listened){ 
            HJ$("txtContent").innerHTML = "";
            HJ$("txtTranslation").innerHTML = "";
            HJ$("intro_content_shift").style.display="block";
            HJ$("intro_content").style.display="none";
        }else{
            HJ$("txtContent").innerHTML = article.content1;
            HJ$("txtTranslation").innerHTML = article.content2;
            HJ$("intro_content_shift").style.display="none";
            HJ$("intro_content").style.display="block";
        } 
        document.title="【"+ article.programName +"】"+ " __[F7切换暂停]__[F8 复读断点]__" + article.title +GetDate(article.showdate);
        //
        currentBBSUrl = article.bbsurl;
        currentBBSUrl_trans= article.bbsurl_trans; 
        //
        bulo_topicID = article.url_bulo;
        //
        HJ$("current_articleimage").innerHTML="<img src="+ article.image +" />";
        HJ$("current_articleimage").className= "passage_info_img "+  ((pID==1)?"img_st":"img_sp");
        var CurrentListen = "";
		CurrentListen+= '<li><a href="/view.aspx?aID='+ articleID +'" title="'+ article.title +'"><b>'+ article.title +'</b></a></li>';
		CurrentListen+= '<li>时长：'+ article.Duration1 +'  '+ GetDate(article.showdate) +'</li>';
		CurrentListen+= '<li>类别：<a href="#" title="'+ article.classname +'">'+ article.classname +'</a> / <span class="gray">'+ article.listencount +'人次</span></li>';
		CurrentListen+= '<li>难度：<img src="/images/star_'+ article.level +'.gif" align="absmiddle" alt="难度'+ article.level +'颗星"/> </li>';
		HJ$("present_passage_info").innerHTML= CurrentListen;
		HJ$("linkstags").innerHTML = article.linkedtags;
		//alert(HJ$("linkdownload").innerHTML);
		HJ$("linkdownload").innerHTML = '<a href="'+ article.media1 +'" target="_blank">音频下载</a>';
        // 
        if(draft!=null){
            var html="<TABLE width='345' cellpadding='2' cellspacing='0'><TR><TD width='165'> ";
            html+= "听写于："+ FormatDateString(draft.publishtime) +"<br /> ";
            html+= "</TD><TD> ";
            html+= "用时："+ draft.timeused +"<br/>";
            html+= "<TD></TR><TR><TD>"; 
            html+= "正确率："+ draft.scorerate +" %(+"+ (draft.money) +"分)<br/>"; 
            html+= "</TD><TD> ";
            html+= "错误："+ draft.errornum +"个单词 [<a href='###'  onclick=\"return ShiftVisible('panel_errorlist');\">详细</a>]<br/>";
            html+= "</TD></TR></TABLE> ";
        
            HJ$("result_panel_infocontent").innerHTML=  html; 
		    // 
            HJ$("result_panel_content").innerHTML = draft.content;  
            HJ$("myvoanote").value = draft.mynote;
            SowErrorWordsList(draft.errorwords.split("|"));
            HJ$("btn_voanotesave").innerHTML=""; 
            //
            HJ$("txtMytrans_content").value = draft.mytrans;
            //
            bbstrans_replayed =draft.bbstrans_replayed;
            HJ$("result_action_history").style.display="block";  
        }else{
            HJ$("txtMytrans_content").value = "";
            HJ$("myvoanote").value = "";
            bbstrans_replayed =false;
            HJ$("result_action_history").style.display="none";  
        }  
        HJ$("msg_fortrans").innerHTML = "编辑翻译稿，并保存"; 
        HJ$("link_replybbstrans").style.display= ((article.url_bbs_trans==0)?"none":"block"); 
        HJ$("panel_noactiving").style.display= ((isActiving)?"none":"block"); 
        ShiftNoteEnable(Listened);
        //
        if(bulo_topicID!=0){
            HJ$("li_txtBBS").style.display="block"; 
        }else{
            HJ$("li_txtBBS").style.display="none";	        
        }
        //
        if(recentListens!=null){
            BindRecentListens(recentListens);
        } 
        //
        HJ$("panel_autoreplybbs").style.display=((Listened)?"none":"block"); 
        if(!Listened){
            if(username=="游客"){
                HJ$("autoreplybbs").checked=false;//((username!="游客")?true:false); 
                HJ$("autoreplybbs").disabled=true;//((username=="游客")?true:false); 
            }else{
                HJ$("autoreplybbs").checked= ((article.url_bbs!=0)?true:false);
                HJ$("autoreplybbs").disabled=((article.url_bbs==0)?true:false);
            }
        }  
        //
        UpdateDraftStatus(); 
        //
        articleLoaded++; 
        ShiftTab2("li_txtListen");
        //
	    HJ$("iframe_bbs").style.display="none";
        //
        LoadSound(article.media1, false);
	    iFrameBBSUrl("about:_blank");
    }else{
		alert(result.error);
    }
    ShowLoadingStatus(false); 
}

//加载文章
function LoadArticle(aID){ 
    if(isListening){
        if(!confirm("当前听写尚未结束，是否终止听写，并加载新文章？")){
            return false;
        }else{
            CancelListen();
        }
    }
    ShowLoadingStatus(true, true); 
    PageClass.LoadArticle(username, aID, LoadArticle_callback);
    return false;
}

//加载相关文章列表
function LoadAboutArticles_callback(result){
    if(!result.error){ 
    }else{ 
    }
    ShowLoadingStatus(false);
}

//加载当前听写的相关文章，更换听写稿时自动加载
function LoadAboutArticles(apID,tags){    
    ShowLoadingStatus(true); 
    PageClass.LoadAboutArticles(apID, tags, LoadAboutArticles_callback);        
}

// =================== 快速索引 ==========================// 
function SearchArticles_callback(result){
    //aList.Add(aDataTable);
    //aList.Add(CurrentPage);
    //aList.Add(PageCount);
    //aList.Add(ArticleCount);
    if(!result.error){ 
        var adt = result.value[0];
        var CurrentPage = result.value[1];
        var PageCount = result.value[2];
        var ArticleCount = result.value[3];  
        // 
        //附带关键词搜索
        var usrKey;
        if(result.value.length>4){
            usrKey= true;
            HJ$("dic_index_list_title").innerHTML ="附加关键词【"+ result.value[4] +"】的索引结果：";
        }else{
            usrKey= false;
            HJ$("dic_index_list_title").innerHTML ="索引结果：";
        }
        if(ArticleCount>0){
            BindArticleInfo("dic_index_list_content", adt);
            var html2=''; 
            //
            var StartPage =Math.max(CurrentPage-2, 1);
            var EndPage =Math.min(StartPage+4, PageCount);
            //
            for(var i=StartPage; i<=EndPage; i++){
                if(i==CurrentPage){
                    html2+= i+"&nbsp;";
                }else{
                    html2+= "<a href='#' onclick='return SearchArticles("+ i +","+ usrKey +");'>["+ i +"]</a>&nbsp;";
                }
            }
            if(CurrentPage< PageCount){
                html2+= "&nbsp;<a href='#' onclick='return SearchArticles("+ (CurrentPage+1) +","+ usrKey +");'><img src='/images/ico_arrow.gif' align='absmiddle'/></a>";
            }
            if(StartPage>3){
                html2 =  "<a href='#' onclick='return SearchArticles(1,"+ usrKey +");'>[1]</a>&nbsp;...&nbsp;" +html2;
            }
            html2 = '<span class="presentpage">页：</span>'+html2;
            HJ$( "dic_index_list_nav" ).innerHTML = html2;
        }else{
            HJ$( "dic_index_list_content" ).innerHTML = "<font color='gray'> 当前搜索范围内，无匹配结果</font>";
            HJ$( "dic_index_list_nav" ).innerHTML = "";
        }
    }else{
        alert(result.error);
    }    
    ShowLoadingStatus(false);
}

//;;;;;;;;;; VOA笔记相关 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 
function ShiftNoteEnable(abool){ 
    HJ$("myvoanote").disabled=!abool;
    if(!abool){
        HJ$("myvoanote").value="听写笔记在保存听写稿后可用：）";
    }else{
        if(HJ$("myvoanote").value=="听写笔记在保存听写稿后可用：）"){
            HJ$("myvoanote").value="";
        }
    }
} 
//
function SaveMyNote_callback(result){
    if(!result.error){ 
        HJ$("btn_voanotesave").innerHTML="保存于"+ FormatTimeString(new Date());
    }else{ 
        HJ$("btn_voanotesave").innerHTML="保存失败，请 [<a href='###' onclick='return SaveMyNote();' class='topmenu' title='"+ result.error +"'>点这里重试</a>]";
    }
}
function SaveMyNote(){ 
    if(HJ$("myvoanote").value.length==0){
        alert("请先输入笔记内容！");
        return 
    }        
    HJ$("btn_voanotesave").innerHTML="保存中 ... <img src='/images/loading.gif' align='absmiddle'/>";
    PageClass.SaveMyNote(articleID, username, HJ$("myvoanote").value, SaveMyNote_callback);   
    return false;
}
function myvoanote_blur(){
    HJ$("myvoanote").className='voanote'; 
}
function myvoanote_focus(){
    currentNote= HJ$("myvoanote").value;
    HJ$("myvoanote").className='voanote_over'; 
}
function wheninputnote(aevent){
    if(!aevent){aevent=window.event;}
    if(aevent.keyCode!=8 && aevent.keyCode!=46){
        if(HJ$("myvoanote").value.length>500){ 
            HJ$("btn_voanotesave").innerHTML = "<font color=red>超过500字符</font>，请 [<a href='###' onclick='return SaveMyNote();' class='topmenu'>点击保存</a>]";
            return false;
        } 
    }
    HJ$("btn_voanotesave").innerHTML = "内容已更改，请 [<a href='###' onclick='return SaveMyNote();' class='topmenu'>点击保存</a>]";
    return true;
}
//;;;;;;;;;;;;;;;;;翻译稿相关;;;;;;;;;;;;;;;;;;;
var lastCtrlkey=false;
function wheninputmytrans(aevent){
    if(!aevent){aevent=window.event;}   
    //
    if(aevent.keyCode!=8 && aevent.keyCode!=46){
        if(HJ$("txtMytrans_content").value.length>4000){ 
            HJ$("msg_fortrans").innerHTML = "<font color=red>超过4000字符的最大篇幅</font>";
            return false;
        }
    } 
    if(aevent.keyCode!=16 && aevent.keyCode!=17 && aevent.keyCode!=18 && aevent.keyCode!=20){
        HJ$("msg_fortrans").innerHTML = "内容已更改，请 [<a href='###' onclick='return SaveMyTrans();' class='topmenu'>及时保存</a>]";
    }
    return true;
}
function ShifttxtContent2(){
    if(HJ$("panel_oritran_en").style.display=="none"){
        HJ$("panel_oritran_en").style.display="block";
        HJ$("txtMytrans_content").style.height="165px";
        HJ$("link_oritran_en").innerHTML='[<a href="###" onclick="return ShifttxtContent2();">隐藏原文</a>]'; 
        HJ$("panel_oritran_en").innerHTML=  HJ$("txtContent").innerHTML; 
        HJ$("panel_oritran_cn").style.display="none";
        HJ$("link_oritran_cn").innerHTML='[<a href="###" onclick="return ShiftTranslation2();">显示译文</a>]';
    }
    else{
        HJ$("panel_oritran_en").style.display="none";
        HJ$("txtMytrans_content").style.height="350px";
        HJ$("link_oritran_en").innerHTML='[<a href="###" onclick="return ShifttxtContent2();">显示原文</a>]';
    } 
}
function ShiftTranslation2(){
    if(HJ$("panel_oritran_cn").style.display=="none"){
        HJ$("panel_oritran_cn").style.display="block";
        HJ$("txtMytrans_content").style.height="165px";
        HJ$("link_oritran_cn").innerHTML='[<a href="###" onclick="return ShiftTranslation2();">隐藏译文</a>]'; 
        HJ$("panel_oritran_cn").innerHTML=  HJ$("txtTranslation").innerHTML; 
        HJ$("panel_oritran_en").style.display="none";
        HJ$("link_oritran_en").innerHTML='[<a href="###" onclick="return ShifttxtContent2();">显示原文</a>]';
    }
    else{
        HJ$("panel_oritran_cn").style.display="none";
        HJ$("link_oritran_cn").innerHTML='[<a href="###" onclick="return ShiftTranslation2();">显示译文</a>]';
    } 
    if(HJ$("panel_oritran_cn").style.display=="none" && HJ$("panel_oritran_en").style.display=="none") 
        HJ$("txtMytrans_content").style.height="350px"; 
}
function SaveMyTrans_callback(result){
    if(!result.error){ 
        if(currentBBSUrl_trans.length!=0){
            HJ$("msg_fortrans").innerHTML="最后保存于"+ FormatTimeString(new Date())+"，"+'[<a href="###" onclick="return Viewbbs(this,2);" target="_blank">参与翻译讨论]</a>';
        }else{
            HJ$("msg_fortrans").innerHTML="最后保存于"+ FormatTimeString(new Date());
        }
    }else{ 
        HJ$("msg_fortrans").innerHTML="保存失败，请 [<a href='###' onclick='return SaveMyNote();' class='topmenu' title='"+ result.error +"'>点这里重试</a>]";
    }
}
function SaveMyTrans(){
    if(HJ$("txtMytrans_content").value.length==0){
        alert("请先输入翻译内容！");
        return 
    }        
    HJ$("msg_fortrans").innerHTML="保存中 ... <img src='/images/loading.gif' align='absmiddle'/>";
    PageClass.SaveMyTrans(articleID, username, HJ$("txtMytrans_content").value, SaveMyTrans_callback);  
    return false;
}
function mytrans_blur(){
    HJ$("txtMytrans_content").className='mytrans'; 
}
function mytrans_focus(){
    currentMyTrans= HJ$("txtMytrans_content").value;
    HJ$("txtMytrans_content").className='mytrans_over'; 
}
//;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
function BindRecentListens(adt){
    var html="谁刚听过："; 
    for(var i=0;i<adt.Rows.length;i++){
        var theRow = adt.Rows[i];
        html+= '<a href="/user/'+ theRow.username +'" target="_blank" title="'+ theRow.scorerate +'%">'+ theRow.username +'</a>&nbsp;';
    }
    HJ$("whojustlisten").innerHTML = html;
}

///处理文章索引结果，动态产生索引文章列表
function BindArticleInfo(aElem, adt){
    var html=""; 
    for(var i=0;i<adt.Rows.length;i++){
        var theRow = adt.Rows[i];
		html+= '<div class="passage_info_ctn">'; 
		if(theRow.listened){ 
		    html+= '	<div class="passage_info_img '+ ((theRow.pID==1)?"img_st":"img_sp") +'"  onclick="LoadArticle('+ theRow.aID +');"><img src="'+CoverSubPath+ theRow.img +'"/><div class="passage_info_draftimg">已听写</div></div>';
		}else{
		    html+= '	<div class="passage_info_img '+ ((theRow.pID==1)?"img_st":"img_sp") +'"  onclick="LoadArticle('+ theRow.aID +');"><img src="'+CoverSubPath+ theRow.img +'"/></div>';
		}
		html+= '	<ul class="passage_info">';
		if(theRow.listened){ 
		    html+= '		<li>标题：<a href="'+ ((theRow.pID==1)?"/st/":"/sp/")+ GetfullDate(theRow.showdate) +'" class="red" title="'+ theRow.subtitle +'" onclick="return LoadArticle('+ theRow.aID +');">'+ theRow.title +'</a></li>';
		}else{
		    html+= '		<li>标题：<a href="'+ ((theRow.pID==1)?"/st/":"/sp/")+ GetfullDate(theRow.showdate) +'" title="'+ theRow.subtitle +'" onclick="return LoadArticle('+ theRow.aID +');">'+ theRow.title +'</a></li>';
		} 
		html+= '		<li>时长：'+ TimeStringFormat2(theRow.duration1) +' <span class="gray">'+ GetDate(theRow.showdate) +'</span></li>';
		html+= '		<li>类别：<a href="#" title="'+ theRow.classname +'" onclick="return IndexClassArticle('+ theRow.cID +');">'+ theRow.classname +'</a> <span class="gray">'+ theRow.listencount +'人次 </span></li>';
		html+= '		<li>难度：<img src="/images/star_'+ theRow.clevel +'.gif" /></li>';
		html+= '	</ul>';
		html+= '	<div class="clear"></div>';
		html+= '</div>';
    }
    HJ$( aElem ).innerHTML = html;   
}

//索引文章，可带关键词
function SearchArticles(aPageIndex, aUserKey){   
    if(aUserKey){
        if(HJ$('index_search_input').value == "在结果中继续搜索") 
            return false; 
    }else{
        HJ$('index_search_input').value = "";
    }      
    ShowLoadingStatus(true);
    var akey= (aUserKey==true)? HJ$('index_search_input').value:""; 
    PageClass.SearchArticles(username, akey, HJ$("search_catagory").value, HJ$("search_cid").value, 0, HJ$("search_year").value, HJ$("search_month").value, aPageIndex, SearchArticles_callback);
    
    return false;
}
function IndexClassArticle(cID){
    HJ$("search_cid").value=cID;
    SearchArticles(1, false);
    ShiftTab(HJ$('dic_lefttab2'), 'left_content2');
}
function IndexByTag(aTag){ 
    HJ$('index_search_input').value=aTag;
    HJ$("search_catagory").value=pID;
    SearchArticles(1, true); 
    ShiftTab(HJ$('dic_lefttab2'), 'left_content2');
    return false;
}

function WhenKeyDown_index_search_input(aevent){
    if(aevent)
        aevent=window.event; 
    if( aevent.keyCode==13){ 
        SearchArticles(1, true);  
    }
}    

// =================== 我的听写稿 ==========================// 
//显示我的听写稿的搜索结果，动态产生html，带分页
function BindDraftInfo(aElem, adt){
    var html=""; 
    for(var i=0;i<adt.Rows.length;i++){
        var theRow = adt.Rows[i];
        html+= '<div class="passage_info_ctn personal_passage_info_ctn">';
        html+= '    <div class="passage_info_img_half '+  ((theRow.pID==1)?"img_st":"img_sp")  +'" onclick="LoadArticle('+ theRow.aID +');"><img src="'+CoverSubPath+ theRow.img +'" class="half"/></div>';
        html+= '    <ul class="passage_info_small">';
        html+= '        <li>';
        html+= '        <a href="'+ ((theRow.pID==1)?"/st/":"/sp/")+ GetfullDate(theRow.showdate) +'"  onclick="return LoadArticle('+ theRow.aID +');" title="'+ theRow.subtitle +'\r\n时长：'+ TimeStringFormat2(theRow.duration1)+'\ 类别：'+theRow.classname+'">';
        html+= '        '+ theRow.title +'';
        html+= '        </a></li> '; 
        html+= '        <li>错词：'+ theRow.errornum +'个 <span class="gray">(正确率:'+ theRow.scorerate +'% +'+ (theRow.money) +'分)</span></li>'; 
        html+= '        <li>听于：'+ FormatDateString(theRow.publishtime) +'  <a href="/doc/'+ theRow.dID +'" target="_blank" title="新窗口中浏览本听写稿"><img src="/images/icon_newwin.gif" align="absmiddle"/></a></li>';
        html+= '    </ul>';
        html+= '    <div class="clear"></div>';
        html+= '</div> '; 
    }
    HJ$( aElem ).innerHTML = html;   
}
function BindDraftInfo_doc(aElem, adt){
    var html=""; 
    for(var i=0;i<adt.Rows.length;i++){
        var theRow = adt.Rows[i];
        html+= '<div class="passage_info_ctn personal_passage_info_ctn">';
        html+= '    <ul class="passage_info_small gray">';
        html+= '        <li><img src="/images/ico_red.gif" align="absmiddle" />';
        html+= '        <a href="/doc/'+ theRow.dID +'" target="_blank">';
        html+= '        '+ theRow.title +'';
        html+= '        </a></li> '; 
        html+= '        <li>&nbsp;&nbsp;错词：'+ theRow.errornum +'个 <span class="gray">(正确率:'+ theRow.scorerate +'% +'+ (theRow.money) +'分)</span></li>'; 
        html+= '        <li>&nbsp;&nbsp;听于：'+ FormatDateString(theRow.publishtime) +'</li>';
        html+= '    </ul>';
        html+= '    <div class="clear"></div>';
        html+= '</div> '; 
    }
    HJ$( aElem ).innerHTML = html;   
}
//我的听写稿搜索回调函数
function ListMyDraft_callback(result){
    //aList.Add(aDataTable);
    //aList.Add(CurrentPage);
    //aList.Add(PageCount);
    //aList.Add(ArticleCount);
    if(!result.error){  
        var adt = result.value[0]; 
        var CurrentPage = result.value[1];
        var PageCount = result.value[2];
        var ArticleCount = result.value[3];  
        //附带关键词搜索
        var usrKey;
        if(result.value.length>4){
            usrKey= true;
            HJ$("dic_personal_list_title").innerHTML ="附加关键词【"+ result.value[4] +"】的过滤结果：";
        }else{
            usrKey= false;
            HJ$("dic_personal_list_title").innerHTML ="过滤结果：";
        }
        if(ArticleCount>0){
            //显示听写稿列表
            if(pagetype=="listen")
                if(usrKey){
                    BindDraftInfo("dic_personal_list_content", adt, result.value[4]);
                }else{
                    BindDraftInfo("dic_personal_list_content", adt, "");
                }
            else
                if(usrKey){
                    BindDraftInfo_doc("dic_personal_list_content", adt, result.value[4]);
                }else{
                    BindDraftInfo_doc("dic_personal_list_content", adt, "");
                }
            //构建分页导航
            var html2='';//1&nbsp;<a href="">[2]</a>&nbsp;<a href="">[3]</a>..<a href="">[10]</a>
            var StartPage =Math.max(CurrentPage-2, 1);
            var EndPage =Math.min(StartPage+4 , PageCount);
            //
            for(var i=StartPage; i<=EndPage; i++){ 
                if(i==CurrentPage){
                    html2+= i+"&nbsp;";
                }else{
                    html2+= "<a href='#' onclick='return ListMyDraft("+ i +","+ usrKey+ ");'>["+ i +"]</a>&nbsp;";
                }
            }
            if(StartPage>3){
                html2 =  "<a href='#' onclick='return ListMyDraft(1,"+ usrKey +");'>[1]</a>&nbsp;...&nbsp;" +html2;
            }
            html2 = '<span class="presentpage">页：</span>' +html2;
            HJ$( "dic_personal_list_nav" ).innerHTML = html2;
        }else{
            HJ$( "dic_personal_list_content" ).innerHTML = "<font color='gray'> 当前搜索范围内，无匹配结果</font>";
            HJ$( "dic_personal_list_nav" ).innerHTML = "";
        }
    }else{
        alert(result.error);
    }  
    ShowLoadingStatus(false);
}
//过滤搜过我的听写稿，可带关键词匹配
function ListMyDraft(aPageIndex, aUserKey){   
    var akey="";
    if(pagetype=="listen"){
        if(aUserKey)
            if(HJ$('personal_search_input').value == "在结果中继续搜索") 
                return false; 
        else
            HJ$('personal_search_input').value = "";
        akey= (aUserKey==true)? HJ$('personal_search_input').value:"";
    }
    ShowLoadingStatus(true);
    PageClass.ListMyDraft(akey, HJ$("mysearch_catagory").value, HJ$("mysearch_cid").value, username, HJ$("mysearch_year").value, HJ$("mysearch_month").value, aPageIndex, ListMyDraft_callback);
	return false;
}
function WhenKeyDown_personal_search_input(aevent){
    if(aevent)
        aevent=window.event; 
    if( aevent.keyCode==13){ 
        ListMyDraft(1, true);  
    }
}
function WhenKeyDown_mail_input(aevent){
    if(!aevent)
        aevent=window.event; 
    if( aevent.keyCode==13){ 
        submail_form_submit();
        stopBubble(aevent); 
        return false;
    }else{ 
        if( aevent.keyCode==27){ 
            showmailform(); 
        }
    }
}
//
function getClasslist_callback(result){
    if(!result.error){ 
        var OptionObj = HJ$(result.value[0]);
        var remainItems = (( result.value[0]=="mysearch_cid" )?0:1);
		for(var i= OptionObj.options.length-1; i>remainItems; i--){
			if(document.all){
				OptionObj.options.remove(i);//Index 
			}else{
				OptionObj.remove(i);//Index 
			}
		}
		//
        var DateList = result.value[1]; 
		BindOptionList( OptionObj, DateList); 
        HJ$(result.value[0]+"_loading").innerHTML="";
        HJ$(result.value[0]+"_loading").style.display="none";
    }else{
    
    }
}
function BindOptionList(aOptionObj, adt){ 
    for(var i=0;i<adt.Rows.length;i++){
        var theRow = adt.Rows[i];
		aOptionObj.options.add(new Option(theRow.classname, theRow.cID));  
    }
}
//
function ShiftClassList(aOptionID){
    var aPID=1;
    if(aOptionID=="search_cid"){
        aPID= HJ$("search_catagory").value;
    }else{
        aPID= HJ$("mysearch_catagory").value;
    }     
    HJ$(aOptionID+"_loading").innerHTML="<img src='/images/loading.gif' align='absmiddle'/>";
    HJ$(aOptionID+"_loading").style.display="block";
    PageClass.getClasslist(aPID, aOptionID, getClasslist_callback);
}
//邮件订阅
function submail_form_submit(){
    //todo: 复制mail值... 
    HJ$("user").value = HJ$("ori_user").value;
    HJ$("action").value = HJ$("ori_mailaction").value; 
    HJ$('submail_form').submit(); 
    //
    HJ$("ori_user").value = "";
    HJ$("ori_mailaction").value = "add";
    showmailform();
}
// ================================= 听写播放器相关 =================================
function voaplayerinit(){
    try{
        setTimeout("voaplayerinit_do();", 250);
        _voaplayer_inited = true; 
    }catch(e){
    }
}
function voaplayerinit_do(){ 
    if(voaplayerinitmp3!=""){  
	    voaPlayer().loadsound(voaplayerinitmp3, false);
    }
}
function shortcut(aevent) {
	if(!aevent) 
		aevent=window.event; 
	if(_voaplayer_inited){
        if(aevent.keyCode==118){  
		    voaPlayer().splaypause();
		    stopBubble(aevent); 
	    }else if(aevent.keyCode==119){ 
		    voaPlayer().srepeat();
		    stopBubble(aevent); 
	    }
		/*else if(aevent.keyCode==120) {
		    voaPlayer().srewind(false);
		    stopBubble(aevent); 
        }*/
	}
} 
function stopBubble(e) { 
	//如果提供了事件对象，则这是一个非IE浏览器 
	if ( e && e.stopPropagation ) 
		//因此它支持W3C的stopPropagation()方法 
		e.stopPropagation(); 
	else 
		//否则，我们需要使用IE的方式来取消事件冒泡 
		window.event.cancelBubble = true; 
}
// 
function LoadSound(mp3file, autostart){
	if(_voaplayer_inited){
	    voaPlayer().loadsound(mp3file, autostart);
	}
    return false;
}
//
function voaPlayer(){
    //return HJ$("hjvoaplayer");
	if (document.all) {
		return document.all.newhjvoaplayer;
	} else {
		if(document["newhjvoaplayer"] instanceof HTMLEmbedElement){
			return document["newhjvoaplayer"];
		}else{
			return document.newhjvoaplayer[1];
		}
	}
}
//
//

function addmyword2_callback(result){  
    var panelObj =HJ$("panel_awd_"+result.taskid);
	//{taskid:,word:,retvalue:}  
    if(result.retvalue=="yes"){
		//添加成功，包括二次添加
		panelObj.innerHTML="<a href='http://bulo.hjenglish.com/mydict/' target='_blank'><img src='/images/icon_awd_ok.gif' align='absmiddle'/></a>";
    }else if(result.retvalue=="no"){
        //添加失败
		panelObj.innerHTML="<a href='http://bulo.hjenglish.com/mydict/' target='_blank'><img src='/images/icon_awd_error.gif' align='absmiddle'/></a>";
    }else if(result.retvalue=="error"){
        //发生错误
		panelObj.innerHTML="<a href='http://bulo.hjenglish.com/mydict/' target='_blank'><img src='/images/icon_awd_error.gif' align='absmiddle'/></a>";
    }else if(result.retvalue=="login"){
        //需要登陆
		panelObj.innerHTML='<a href="#" onclick="AddWord();return false;"><img src="http://dict.hjenglish.com/images/btn_myword_add.gif" align="absmiddle"/></a>';
		if(confirm("只有登录沪江部落后，才能添加自己的生词，现在是否登录？")){
			window.open("http://bulo.hjenglish.com/login.aspx?Reset=1&ReturnUrl="+ escape("http://bulo.hjenglish.com/mydict/"));
		}
    }else{
        //添加错误
    }
}
//
function AddWord(ataskID, aword){
	document.getElementById("panel_awd_"+ ataskID).innerHTML="<img src='/images/loading.gif' align='absmiddle'/>";
	//addmyword(word, comment, langs, callbackfunctionname, taskid)
	hjdict_addmyword(aword,'', 'en', 'addmyword2_callback', ataskID);
}
function DoFlashTrace(Msg){  
    HJ$("tbox_input").value =Msg + "\r\n"+ HJ$("tbox_input").value; 
}
function showmailform(){
    ShiftVisible("mail_action1");
    ShiftVisible("mail_action2");
}

var old_word = "";
function QueryDict_VoaWord(aword){
    if( aword!=old_word ){
        old_word=aword;
        iFrameDictUrl("http://dict.hjenglish.com/web/"+ aword);
        ShiftTab(HJ$('dic_lefttab5'), 'left_content5');
    }
}


function ShiftPresentContent(){
    ShiftVisible('intro_content_shift'); 
    ShiftVisible('intro_content'); 
    return false;
}
function Viewbbs(aLinkObj, atype){
    if(atype==1){
        aLinkObj.href= currentBBSUrl;
    }else{
        aLinkObj.href= currentBBSUrl_trans;
    } 
    return true;
}
///
///
///
//一般听力工具型支持：
//
function SetCustomArticle(abool){
    if(abool){
        HJ$("panel_customset").style.display="block";
        HJ$("player_ctn").style.display="none";
    }else{
        HJ$("panel_customset").style.display="none";
        HJ$("player_ctn").style.display="block";
    }
    return false;
}

function SetCustomArticle_Do(){
    var cus_mp3=HJ$("cus_mp3").value;
    var engli=HJ$("cus_text").value;
    if(cus_mp3.length==0){
        alert("请设定mp3地址！");
        return false;
    }
    if(engli.length==0){ 
        if(!confirm("听力原文尚未设置，原文空缺的听写不提供比对，是否继续？")){
            return false;
        }
    }
	voaplayerinitmp3 = cus_mp3;
    // 
    HJ$("txtContent").innerHTML = engli;
    HJ$("txtTranslation").innerHTML = "无译文";
    HJ$("intro_content_shift").style.display="block";
    HJ$("intro_content").style.display="none";
    HJ$("present_passage_info").innerHTML= "自定义内容无简介";
    HJ$("linkstags").innerHTML = "--";
    HJ$("linkdownload").innerHTML = "--"; 
    HJ$("programName").innerHTML = "自定义听写"; 	
    iFrameBBSUrl("about:_blank");
    document.title="【自定义听写】"+ " __[F7切换暂停]__[F8 复读断点]__ 沪江小T";
    
    pID=0;
    _NewDraftResult={};
    articleID=-1;
    bulo_topicID=0;
    Listened=false;
    isActiving = false;
    initErrorwords="";
    currentBBSUrl="";
    currentBBSUrl_trans="";
    currentWordcount=engli.split(" ").length;
    UpdateDraftStatus(); 
    HJ$("player_ctn").innerHTML = GetFlashCode("newhjvoaplayer","/common/voa_player_new.swf", "_file="+cus_mp3, 559, 61, true); 
    ShowLoadingStatus(false); 
    HJ$("panel_customset").style.display="none"; 
    HJ$("player_ctn").style.display="block";
    HJ$("txtSummary").innerHTML="自定内容无概要";
}

//设置字体大小：12--18px之间
function ShiftFontSize(aSize){  
    ShiftFontSize_do( Math.max(12, Math.min(24,myfontSize+ aSize)) );
}

function ShiftFontSize_do(amyfontSize){ 
    myfontSize=amyfontSize
    HJ$("tbox_input").style.fontSize= myfontSize+ "px";
    HJ$("result_panel_content").style.fontSize= myfontSize+ "px";
    HJ$("txtContent").style.fontSize= myfontSize+ "px";
    HJ$("panel_oritran_en").style.fontSize= myfontSize+ "px";    
    if( myfontSize==12){
        HJ$("fontsize_min").innerHTML="<img src='/images/minus00.gif' />"; 
    }else{
        HJ$("fontsize_min").innerHTML="<img src='/images/minus01.gif' />"; 
    }
    if( myfontSize==24){
        HJ$("fontsize_max").innerHTML="<img src='/images/plus00.gif' />"; 
    }else{
        HJ$("fontsize_max").innerHTML="<img src='/images/plus01.gif' />"; 
    }
    //
    setcookie("voafsz", myfontSize, 999999999, "/");
}
function isMatch(){
    return ((currentArticleTags.indexOf("比赛")!=-1 || currentClassname.indexOf("大赛")!=-1))
}
//
function HintMatchinfo(){
	if(isMatch()){
		alert("感谢您参加“"+currentClassname+"”，您的听写稿已提交\n\n点击确定查看您的参赛听写稿！");
		document.location.href = "/contest/goto_match.aspx";
	}
}
function onpageLoad(){
	if(isMatch()){	   
		if(username=="游客"){
			alert("本文为听写比赛活动专用，游客无法参赛，请先登陆！：）");	  
			document.location.href = "http://voa.hjenglish.com";
		}else{
			if(confirm("欢迎您参加“"+currentClassname+"”，本参赛文章只有一次在线听写机会，点击【确定】将马上开始听写！")){   
				setTimeout(StartListen, 1000); 
			}else{
				document.location.href = "http://voa.hjenglish.com";
			}
		}
	}
}
function Voabeforeunload(){
	/*if(isMatch()){	   
		if(confirm("欢迎您参加“"+currentClassname+"”，本参赛文章只有一次在线听写机会，点击【确定】后将立即开始听写！")){   
			alert("点了确定");
		}else{ 
			alert("点了取消");
		}
	}*/ 
}
function voa_oncopy(){
	return !isMatch();
}		
function voa_onpaste(){	 
	if(isMatch()){
		alert("听写比赛进行中，粘贴功能临时禁用");
		return false;
	}else{
		return true;
	}
}
function voa_ondrop(){ 
	return !isMatch();
}